<template>
  <el-form
    :model="form"
    status-icon
    :rules="rules"
    ref="form"
    label-width="100px"
    class="login-container"
  >
    <h3 class="login_title">系统登入</h3>
    <!-- 账号 -->
    <el-form-item
      label="用户名"
      label-width="88px"
      prop="username"
      class="username"
    >
      <el-input
        type="input"
        v-model="form.username"
        autocomplete="off"
        placeholder="请输入账号"
      ></el-input>
    </el-form-item>
    <!-- 密码 -->
    <el-form-item
      label="密码"
      label-width="88px"
      prop="password"
      class="password"
    >
      <el-input
        type="password"
        v-model="form.password"
        autocomplete="off"
        placeholder="请输入密码"
      ></el-input>
    </el-form-item>
    <!-- 登录 -->
    <el-form-item class="login_submit">
      <el-button type="primary" @click="login" class="login_submit"
        >登录</el-button
      >
    </el-form-item>
  </el-form>
</template>


<script>
// import Mock from 'mockjs'
import {getMenu} from '../../../api/data'
export default {
  name: "login",
  data() {
    return {
      form: {},
      rules: {
        // 用户名
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          {
            min: 3,
            message: "用户名长度不能小于3位",
            trigger: "blur",
          },
        ],
        // 密码
        password: [
          {
            required: true,
            message: "请输入密码",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    login() {
        getMenu(this.form).then(res =>{
            console.log(res,"res");
            if(res.code === 20000){
                console.log("触发了20000");
                this.$store.commit('clearMenu')
                this.$store.commit('setmenu',res.data.menu)
                this.$store.commit('setToken',res.data.token)
                this.$store.commit('addMenu',this.$router)
                this.$router.push({name:'home'})
            }else{
                console.log("触发了");
                this.$message.warning(res.data.message)
            }
        }).catch(()=>{})
        // const token = Mock.random.guid()
        // this.store.commit('setToken',token)
        // this.$router.push({name:'home'})
    },
  },
};
</script>

<style lang="less" scoped>
.login-container {
  border-radius: 0.9375rem;
  background-clip: padding-box;
  margin: 11.25rem auto;
  width: 21.875rem;
  padding: 2.1875rem 2.1875rem 0.9375rem 2.1875rem;
  background-color: #fff;
  border: 0.0625rem solid #eaeaea;
  box-shadow: 0 0 1.5625rem #cec6c6;
}
.login_title {
  margin: 0px auto 2.5rem auto;
  text-align: center;
  color: #505458;
}
.login_submit {
  margin: 0.625rem auto 0px auto;
}
</style>